import "./exports/init";
import telegram from "./exports/telegram";
import jApi from "./exports/jmacApi";
import message from "./middlewares/message";
import inline from "./middlewares/inline";
import button from "./middlewares/button";
import commanderInstance from "./exports/commanderInstance";

import "./exports/registerCommands";

setInterval(async () => {
    const res = await jApi.ping();
    if (!res.result) {
        telegram.api.sendMessage({
            chat_id: process.env.CHAT_TO_WARNINGS,
            text: `Внимание!\nПолучил ошибку, попытавшись достучаться до сервака.\n\n⛔${res.message}`,
        });
    }
}, 300 * 1000);

telegram.updates.on("message", message);
telegram.updates.on("message", commanderInstance.middleware);
telegram.updates.on("inline_query", inline);
telegram.updates.on("callback_query", button);

telegram.updates.startPolling().then(() => {
    console.log("updates started");
});
